#include<iostream>
#include<cstring>
using namespace std;
const int N = 2e4 + 10, M = 2 * N;
int h[N], e[M], ne[M], idx;
int sz[N];
int n;
int ma;
int ans = 1e9, ans_ver;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int fa)
{
	sz[u] = 1;
	int ma1 = 0;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != fa) {
			dfs(j, u);
			ma1 = max(ma1, sz[j]);
			sz[u] += sz[j];
		}
	}
	//cout << "u==" << u << "   n-sz[u]==" << n - sz[u] << endl;
	ma1 = max(ma1, n - sz[u]);
	if (ans > ma1) {
		ans = ma1;
		ans_ver = u;
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		memset(h, -1, sizeof(h));
		memset(e, 0, sizeof(e));
		memset(ne, 0, sizeof(ne));
		memset(sz, 0, sizeof(sz));
		ans = 1e9, ans_ver = 0;
		idx = 0;
		for (int i = 0; i < n - 1; i++) {
			int a, b;
			cin >> a >> b;
			add(a, b);
			add(b, a);
		}
		dfs(1, 0);
		/*for (int i = 1; i <= n; i++) {
			cout << "u===" << i << "   sz[u]==" << sz[i] << endl;
		}*/
		cout << ans_ver << " " << ans << endl;
	}
	return 0;
}